﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Reflection;
using Metaspec;

// Formatter example.

namespace FormatterExample
{
	class Program
	{
		static void Main(string[] args)
		{
			//creating project
			ICsProject project = ICsProjectFactory.create(project_namespace.pn_project_namespace);
			project.setBuildEntityModel (false);
			
			//adding C# file
			string directory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"..\..");
			string path = Path.Combine(directory, "Test.cs");
			char[] buffer = File.ReadAllText(path).ToCharArray();
			ICsFile file = ICsFileFactory.create(buffer, path);
			project.addFiles(file);

			//parsing
			project.parse(false,false);

			//calling formatter
			CsFormatter formatter = new CsFormatter();
			formatter.generate(file.getCompilationUnit());
			string formattedText = formatter.getGeneratedText();

			//saving file
			File.WriteAllText(Path.Combine(directory, "TestOut.cs"), formattedText);
		}
	}
}
